package bis;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

public class FLBookMgr extends FLBaseMgr {

    void setdelete(String bm) {
        QueryStr = "select bm from tblBooks where Bm='" + bm + "'";
        UpdateStr = "delete from tblBooks where Bm='" + bm + "'";
        this.BaseDelete();
    }

    private ArrayList GetDate() {
        ArrayList list = new ArrayList();
        ResultSet rs = super.Query();
        try {
            while (rs.next()) {
                FLBook flc = new FLBook(rs.getString(1), rs.getString(2), rs.getString(3), rs.getString(4), rs.getString(5), FLUtility.GetImSimpleFormatTime(rs.getString(6)), rs.getString(7), rs.getInt(8), rs.getString(9), rs.getString(10), rs.getString(11), rs.getString(12));
                list.add(flc);
            }
        } catch (SQLException ex) {
            Logger.getLogger(FLBookMgr.class.getName()).log(Level.SEVERE, null, ex);
        }
        if (list.isEmpty()) {
            return null;
        } else {
            return list;
        }
    }

    public ArrayList GetDateById(String id) {
        QueryStr = "select * from tblBooks where Bm='" + id + "'";
        return GetDate();
    }

    public ArrayList GetDateByclass(String id) {
        QueryStr = "select * from tblBooks where lxbm='" + id + "'";
        return GetDate();
    }

    public ArrayList getDateByFindOption(String key, String id) {
        QueryStr = "select * from tblBooks where " + key + "='" + id + "'";
        return GetDate();
    }

    public ArrayList GetAllDate() {
        QueryStr = "select * from tblBooks";
        return GetDate();
    }

    public void setUpdate(FLBook flb) {
this.setdelete(flb.Bm);
this.Insert(flb);
    }

    public boolean Insert(FLBook flb) {
        flb.formname = "tblBooks";
        String c1 = "insert into tblBooks(Bm, mc, author, publisher, pubDate, Isbn, price, Lxbm, Ym, picPath, content) VALUES('" + flb.getmaxidbybm() + "','" + flb.mc + "','" + flb.author + "','" + flb.publisher + "','" + FLUtility.GetSimpleFormatTime(flb.pubDate)+ "','" + flb.isbn + "'," + flb.price + ",'" + flb.lxbm + "','" + flb.ym + "','" + flb.picPath + "','" + flb.content + "')";
        InsertStr = c1;
        return super.Insert();
    }

    public FLBookMgr() {
    }
}
